Back to course home
0% completed
Vote For New Content
Microsoft Hard Problems
Regular Expression Matching (hard)
Solution: Regular Expression Matching
First Missing Positive (hard)
Solution: First Missing Positive
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Sliding Window Maximum (hard)
Solution: Sliding Window Maximum
Count Unique Characters of All Substrings of a Given String (hard)
Solution: Count Unique Characters of All Substrings of a Given String
Word Ladder (hard)
Solution: Word Ladder
Word Ladder II (hard)
Solution: Word Ladder II
Number of Flowers in Full Bloom (hard)
Solution: Number of Flowers in Full Bloom
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Find Original Array From Doubled Array (medium)
Problem Statement
A doubled array changed is formed from the original array after appending twice the value of each element in the original array and randomly shuffling elements in the updated original array.
Given an array changed, return the original array if changed is a valid doubled array. Otherwise, return empty array.
Examples
-
Example 1:
- Input:
changed = [2,4,1,8] - Expected Output:
[1,4] - Justification: The original array [1,4] is doubled to form [2,4,1,8] (1's double is 2, and 4's double is 8).
- Input:
-
Example 2:
- Input:
changed = [6,3,0,0] - Expected Output:
[0,3] - Justification: The original array [0,3] is doubled to form [6,3,0,0] (0's double is 0, and 3's double is 6).
- Input:
-
Example 3:
- Input:
changed = [1, 2, 2, 4, 4, 8, 16, 32] - Expected Output:
[1, 2, 4, 16] - Justification: The original array [1, 2, 4, 16] is doubled to form [1, 2, 2, 4, 4, 8, 16, 32] (1's double is 2, 2's double is 4, 4's double is 8, and 16's double is 32).
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Restore IP Addresses
Solution: Find Original Array From Doubled Array
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself